<template>
	<view class="container-order">
		<view class="order-box">
			<view class="order-box-flex" v-if="addressInfo.name">
				<image class="location-img" src="/static/message/location.png" mode=""></image>
				<view class="location-content">
					<view class="content-top">
						{{addressInfo.name}} <text>{{addressInfo.phone}}</text>
					</view>
					<view class="content-bottom">
						{{addressInfo.Area.province}}{{addressInfo.Area.city}}{{addressInfo.Area.region}}{{addressInfo.detail}}
					</view>
				</view>
				<image @click="navigator('/pages/message/deliveryAddress/deliveryAddress')" class="right-img"
					src="/static/message/right.png" mode=""></image>
			</view>
			<view class="add-ress" v-else
				@click="redirecttor('/pages/message/deliveryAddress/deliveryAddress?goosInfo='+JSON.stringify(goosInfo))">
				<view class="">
					点击添加地址</view>
				<image class="right-img" src="/static/message/right.png" mode=""></image>
			</view>
			<image class="adress-img" src="/static/message/adress.png" mode=""></image>
		</view>
		<view class="detail-bottom-btn" @click="sendGood">
			发货
		</view>
	</view>
</template>

<script>
	import orderObj from '@/components/orderObj.vue'
	export default {
		components: {
			orderObj
		},
		data() {
			return {
				confirmType: 1, //1确认订单 2 发货
				goosInfo: {},
				addressInfo: {}, //地址信息
				remarks: '',
				goods_id: '',
			}
		},
		onLoad(options) {
			this.goods_id = options.goods_id
		},
		onShow() {
			if (uni.getStorageSync('addressInfo')) {
				this.addressInfo = uni.getStorageSync('addressInfo')
				this.goosInfo = uni.getStorageSync('goodsInfo')
			} else {
				this.init(); //根据商品id获取默认地址
			}
		},
		methods: {
			// 发货
			sendGood() {
				this.$http('orders.applyShipping', {
					goods_id: this.goods_id,
					address_id: this.addressInfo.id
				}, '查询中...').then(res => {
					if (res.code == 1) {
						this.redirecttor('/pages/index/purchaseSuccess/purchaseSuccess?typeImg=' + 1 + '&title=' +
							'发货成功' + '&typeBtn=' + 2)
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
			init() {
				this.$http('other.getDefaultDetail', {}, '查询中...').then(res => {
					if (res.code == 1) {
						this.addressInfo = res.data
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
			exchange() {
				this.$http('integral.submitOrder', {
					goods_id: this.goosInfo.id,
					remarks: this.remarks,
					address_id: this.addressInfo.id
				}, '获取中...').then(res => {
					if (res.code == 1) {
						this.redirecttor('/pages/index/purchaseSuccess/purchaseSuccess?typeImg=' + 1 + '&title=' +
							'兑换成功' + '&typeBtn=' + 2)
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
			// 跳转
			redirecttor(url) {
				uni.redirectTo({
					url: url
				})
			},
			// 跳转
			navigator(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F6F7F9;
	}

	.container-order {
		padding: 20rpx;

		.order-box {
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 20rpx;
			margin-bottom: 20rpx;

			.add-ress {
				display: flex;
				justify-content: space-between;

				.right-img {
					width: 12rpx;
					height: 22rpx;
					margin-top: 10rpx;
				}
			}

			.order-box-flex {
				display: flex;
				justify-content: space-between;

				.location-img {
					width: 60rpx;
					height: 60rpx;
					margin-top: 40rpx;
				}

				.location-content {
					width: 550rpx;

					.content-top {
						font-weight: bold;
						font-size: 32rpx;
						color: #333333;

						text {
							margin-left: 20rpx;
						}
					}

					.content-bottom {
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
						margin-top: 20rpx;
					}
				}

				.right-img {
					width: 12rpx;
					height: 22rpx;
					margin-top: 60rpx;
				}
			}

			.adress-img {
				width: 100%;
				height: 6rpx;
			}
		}
	}

	.detail-bottom {
		width: 100%;
		height: 90rpx;
		background: #FFFFFF;
		position: fixed;
		z-index: 200;
		bottom: 0;
		display: flex;
		justify-content: space-between;

		.detail-bottom-left {
			font-weight: bold;
			font-size: 24rpx;
			color: #DD0403;
			margin: 30rpx 0 0 30rpx;

			.all-money {
				font-weight: 400;
				font-size: 28rpx;
				color: #1A1A1A;
			}

			text {
				font-size: 32rpx;
			}
		}

		.detail-bottom-right {
			width: 280rpx;
			height: 90rpx;
			background: #287E34;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 90rpx;
			text-align: center;
		}
	}

	.detail-bottom-btn {
		position: fixed;
		z-index: 200;
		bottom: 30rpx;
		width: 686rpx;
		height: 88rpx;
		background: linear-gradient(90deg, #6AAE2B 0%, #1B7E38 100%);
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		left: 50%;
		transform: translate(-50%);
		border-radius: 50rpx;
	}
</style>